<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>注册</title>
    <style>
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
            font-family: 'Segoe UI', system-ui, sans-serif;
        }

        body {
            background-color: #f5f5f5;
            display: flex;
            justify-content: center;
            align-items: center;
            min-height: 100vh;
            padding: 20px;
        }

        .register-container {
            background-color: white;
            width: 100%;
            max-width: 350px;
            padding: 30px;
            border-radius: 8px;
            box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
        }

        .register-container h1 {
            text-align: center;
            color: #333;
            margin-bottom: 25px;
            font-size: 24px;
        }

        .input-group {
            margin-bottom: 15px;
        }

        .input-group label {
            display: block;
            margin-bottom: 6px;
            color: #555;
            font-size: 14px;
        }

        .input-group input {
            width: 100%;
            padding: 10px 12px;
            border: 1px solid #ddd;
            border-radius: 4px;
            font-size: 16px;
            transition: border 0.3s;
        }

        .input-group input:focus {
            border-color: #4285f4;
            outline: none;
        }

        .password-group {
            position: relative;
        }

        .toggle-password {
            position: absolute;
            right: 10px;
            top: 50%;
            transform: translateY(-50%);
            background: none;
            border: none;
            color: #888;
            cursor: pointer;
        }

        .terms {
            margin: 15px 0 25px;
            font-size: 14px;
            color: #555;
        }

        .terms a {
            color: #4285f4;
            text-decoration: none;
        }

        .terms a:hover {
            text-decoration: underline;
        }

        .register-btn {
            width: 100%;
            padding: 12px;
            background-color: #4285f4;
            color: white;
            border: none;
            border-radius: 4px;
            font-size: 16px;
            font-weight: 500;
            cursor: pointer;
            transition: background 0.3s;
        }

        .register-btn:hover {
            background-color: #3367d6;
        }

        .login-link {
            text-align: center;
            margin-top: 20px;
            font-size: 14px;
            color: #555;
        }

        .login-link a {
            color: #4285f4;
            text-decoration: none;
        }

        .login-link a:hover {
            text-decoration: underline;
        }

        .back-link {
            text-align: center;
            margin-top: 15px;
            font-size: 14px;
        }

        .back-link a {
            color: #666;
            text-decoration: none;
        }

        .back-link a:hover {
            text-decoration: underline;
        }
    </style>
</head>
<body>
    <div class="register-container">
        <h1>用户注册</h1>
        <!-- 添加了action和method属性 -->
        <form id="registerForm" action="/api/register" method="POST">
            <!-- 用户名输入，添加了name属性 -->
            <div class="input-group">
                <label for="username">用户名</label>
                <input type="text" id="username" name="username" placeholder="请设置用户名" required>
            </div>

            <!-- 邮箱输入，添加了name属性 -->
            <div class="input-group">
                <label for="email">邮箱</label>
                <input type="email" id="email" name="email" placeholder="请输入邮箱" required>
            </div>

            <!-- 密码输入，添加了name属性 -->
            <div class="input-group password-group">
                <label for="password">密码</label>
                <input type="password" id="password" name="password" placeholder="请设置密码" required>
                <button type="button" class="toggle-password" id="togglePassword">👁️</button>
            </div>

            <!-- 确认密码输入，添加了name属性 -->
            <div class="input-group password-group">
                <label for="confirmPassword">确认密码</label>
                <input type="password" id="confirmPassword" name="confirmPassword" placeholder="请再次输入密码" required>
                <button type="button" class="toggle-password" id="toggleConfirmPassword">👁️</button>
            </div>

            <!-- 服务条款，添加了name属性 -->
            <div class="terms">
                <label>
                    <input type="checkbox" name="agreeTerms" required> 我同意<a href="#">服务条款</a>和<a href="#">隐私政策</a>
                </label>
            </div>

            <button type="submit" class="register-btn">注册</button>

            <p class="login-link">
                已有账号？<a href="login.html">立即登录</a>
            </p>

            <p class="back-link">
                <a href="index.html">返回首页</a>
            </p>
        </form>
    </div>

    <script>
        // 密码显示/隐藏切换
        function setupPasswordToggle(toggleBtnId, passwordInputId) {
            const toggleBtn = document.getElementById(toggleBtnId);
            const passwordInput = document.getElementById(passwordInputId);
            
            toggleBtn.addEventListener('click', () => {
                const type = passwordInput.getAttribute('type') === 'password' ? 'text' : 'password';
                passwordInput.setAttribute('type', type);
                toggleBtn.textContent = type === 'password' ? '👁️' : '👁️‍🗨️';
            });
        }
        
        // 设置两个密码框的显示/隐藏功能
        setupPasswordToggle('togglePassword', 'password');
        setupPasswordToggle('toggleConfirmPassword', 'confirmPassword');

        // 表单提交处理
        document.getElementById('registerForm').addEventListener('submit', (e) => {
            // 前端验证
            const password = document.getElementById('password').value;
            const confirmPassword = document.getElementById('confirmPassword').value;
            
            if (password !== confirmPassword) {
                e.preventDefault();
                alert('两次输入的密码不一致，请重新输入');
                return;
            }
            
            if (password.length < 6) {
                e.preventDefault();
                alert('密码长度不能少于6位');
                return;
            }
            
            // 如果需要使用AJAX提交，可以取消默认提交行为
            // e.preventDefault();
            // 然后使用fetch或axios发送请求
            console.log('注册信息将提交到:', '/api/register');
        });
    </script>
</body>
</html>
